//
//  StatusForwardCell.swift
//  01MicroBlog
//
//  Created by Apple on 15/8/4.
//  Copyright © 2015年 heima. All rights reserved.
//

import UIKit

class StatusForwardCell: StatusCell {

    // 这里重写set方法不会影响父类的set方法，这里只需要设置自己的属性就行
   override var status:Status? {
        didSet{
            let name = status?.retweeted_status?.user?.name ?? ""
            let text = status?.retweeted_status?.text ?? ""
            
            forwardlabel.text = "@" + name  + ":" + text
        }
    }
    
    override func setUpUI() {
        super.setUpUI()
        
        contentView.insertSubview(backBtn, belowSubview: pictureView!)
        contentView.insertSubview(forwardlabel, aboveSubview: backBtn)
        
        backBtn.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView:contentLabel , size: nil, offset: CGPoint(x: -margin, y: margin))
        backBtn.ff_AlignVertical(type: ff_AlignType.TopRight, referView:bottomView, size: nil)
        
        forwardlabel.ff_AlignInner(type: ff_AlignType.TopLeft, referView: backBtn, size: nil, offset: CGPoint(x: margin, y: margin))
        
        
        // 先定义一个给定的图片约束，后续再修改
        let cons = pictureView!.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: forwardlabel, size: CGSize(width: 290, height: 290), offset: CGPoint(x: 0, y: margin))
        
        // 设置图片宽高的约束，保证图片可见
        pictureWidthCons = pictureView!.ff_Constraint(cons, attribute: NSLayoutAttribute.Width)
        pictureHeightCons = pictureView!.ff_Constraint(cons, attribute: NSLayoutAttribute.Height)
        pictureTopCons = pictureView?.ff_Constraint(cons, attribute: NSLayoutAttribute.Top)
        
    }
    
    // 懒加载转发文字
    private lazy var forwardlabel:UILabel = {
       let label = UILabel(fontSize: 14, fontColor: UIColor.darkGrayColor())
        label.numberOfLines = 0
        label.preferredMaxLayoutWidth = UIScreen.mainScreen().bounds.size.width - margin * 2
        return label
    }()
    
    // 懒加载灰色按钮
    private lazy var backBtn:UIButton = {
        
        let button = UIButton()
        button.backgroundColor = UIColor(white: 0.8, alpha: 1.0)
        
        return button
    }()
}
